// [[ OnflowGenerator File UUID: ba6b860f9b664680bd0c42779af1ef4d  ]]
package com.itdct.onflow.system.log.service

import com.itdct.onflow.core.constant.CommonString
import com.itdct.onflow.core.constant.ReturnCode
import com.itdct.onflow.core.extend.*
import com.itdct.onflow.core.vo.RespPageVo
import com.itdct.onflow.core.vo.RespVo
import com.itdct.onflow.system.common.base.BaseSysService
import com.itdct.onflow.system.common.context.Context
import com.itdct.onflow.system.common.extend.dict
import com.itdct.onflow.system.log.entity.SysLoginLogEntity
import com.itdct.onflow.system.log.mapper.SysLoginLogMapper
import com.itdct.onflow.system.log.qo.SysLoginLogEditQo
import com.itdct.onflow.system.log.qo.SysLoginLogSearchQo
import com.itdct.onflow.system.log.vo.SysLoginLogDetailVo
import com.itdct.onflow.system.log.vo.SysLoginLogListVo
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

/**
 * @author DCTANT
 * @date 2025-09-22 16:17:05
 * @version 1.0
 * @description 系统登录日志服务
 */
@Service
class SysLoginLogService(
    val sysLoginLogMapper: SysLoginLogMapper
) : BaseSysService() {

    @Transactional(rollbackFor = [Exception::class])
    fun add(qo: SysLoginLogEditQo, context: Context): RespVo<Long> {
        val addEntity = qo.toEntity(SysLoginLogEntity::class.java)
        val id = sysLoginLogMapper.insertEx(addEntity)
        return success(id)
    }

    @Transactional(rollbackFor = [Exception::class])
    fun update(qo: SysLoginLogEditQo, context: Context): RespVo<Unit> {
        val updateEntity = sysLoginLogMapper.selectByIdEx(qo.id)
        qo.injectValue(updateEntity)
        sysLoginLogMapper.updateEx(updateEntity)
        return success()
    }

    fun delete(qo: SysLoginLogEditQo, context: Context): RespVo<Unit> {
        val ids = qo.ids ?: fail(ReturnCode.LACK_PARAM, CommonString.REQUIRE_DELETE_ID_LIST)
        val deleteEntities = sysLoginLogMapper.selectByIdsEx(ids)
        sysLoginLogMapper.deleteBatchEx(deleteEntities)
        return success()
    }

    fun detail(qo: SysLoginLogSearchQo, context: Context): RespVo<SysLoginLogDetailVo> {
        val id = qo.id ?: fail(ReturnCode.LACK_PARAM, CommonString.REQUIRE_ID)
        val vo = sysLoginLogMapper.findById(id) ?: fail(CommonString.ENTITY_NOT_FOUND_USAGE("系统登录日志", id))
        return success(vo.dict())
    }

    fun page(qo: SysLoginLogSearchQo, context: Context): RespPageVo<SysLoginLogListVo> {
        startPage(context)
        val pageData = sysLoginLogMapper.findByList(qo)
        return successPage(pageData.dict())
    }

// [[ OnflowGenerator Range (- selectFunctions -) Start ]]

// [[ OnflowGenerator Range (- selectFunctions -) End ]]
}